﻿using AutoMapper;
using Newtonsoft.Json;
using Read.Entity;
using Read.VModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MedicineWeb.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Index()
        {
            return View();
        }
        ReadDBEntities db = new ReadDBEntities();
        public ContentResult NewArticles()
        {
            
            List<int> authors = db.RssTagRels.Where(p => p.TagId == 3).Select(p=>p.RssId).ToList();
            List<Article> article = db.Articles.Where(p => authors.Contains(p.RssId)).OrderByDescending(p=>p.Id).Take(20).ToList();
            List<ArticleV> result = Mapper.Map<List<ArticleV>>(article);
            return Content(JsonConvert.SerializeObject(result));
        }
        public ContentResult Bloger()
        {
            List<int> authors= db.RssTagRels.Where(p => p.TagId == 3).Select(p => p.RssId).ToList();
            List<RssUrl> rss = db.RssUrls.Where(p => authors.Contains(p.Id)).ToList();
            return Content(JsonConvert.SerializeObject(rss));
        }
        public ContentResult Websites()
        {
            List<WebSite> result = db.WebSites.Where(p => p.TagId == 3).ToList();
            return Content(JsonConvert.SerializeObject(result));
        }
        public ContentResult Books()
        {
            List<Book> result = db.Books.Where(p => p.Id > 0).ToList();
            return Content(JsonConvert.SerializeObject(result));
        }
    }
}
